const BaseService = require("./base");

class Service extends BaseService {
	constructor(...args) {
		super(...args);
		this.table = "menu";
	}

	async list(pageNum, pageSize, where) {
		const parent = await this.app.mysql.select("menu", {
			where: {
				pid: 0,
				...where
			},
			orders: [["id", "asc"]],
			limit: pageSize,
			offset: (pageNum - 1) * pageSize
		});

		const children = await this.app.mysql.query(
			`SELECT * FROM menu WHERE pid > 0`
		);

		// 查询总数
		const total = await this.app.mysql.count(this.table, {
			pid: 0,
			...where
		});
		return {
			data: {
				parent,
				children
			},
			total,
			pageNum,
			pageSize
		};
	}
}

module.exports = Service;
